----------- 
-- Author: Bojun Chen
-- Date: 2021-09-10 14:36:26
-- Desc: 基础视图模型
----------- 

local BaseUIWinLife = BaseUIWinLife
local BaseViewModel = class("BaseViewModel", BaseUIWinLife)


function BaseViewModel:ctor()
    self.fieldTab = {}
    self.callBacks = {}
    self:SetMetaTab()
end

--[[
    @desc: 设置元方法之新设值方法
    author:Bojun Chen
    time:2021-09-16 15:39:22
    @return:
]]
function BaseViewModel:SetMetaTab()
    if self.metaTab == nil then
        self.metaTab = getmetatable(self) == nil and {} or getmetatable(self)
    end

    local this = self
    this.metaTab.__newindex = function(tab, key, val)
        local fieldConfig = this.fieldTab[key]
        if fieldConfig ~= nil then
            if fieldConfig.callback ~= nil then
                fieldConfig.callback(fieldConfig.viewTab, this.metaTab[key], val)
            end
        end
        this.metaTab[key] = val
    end
end

--[[
    @desc: 注册回调
    author:Bojun Chen
    time:2021-09-16 15:39:52
    --@field: 字段名
	--@callback: 回调
	--@viewTab: view对象
    @return:
]]
function BaseViewModel:RegistField(field, callback, viewTab)
    self.fieldTab[field] = {callback = callback, viewTab = viewTab}
end


function BaseViewModel:Init()
    self:OnInit()
end


function BaseViewModel:Enable(...)
    self:OnEnable(...)
end


function BaseViewModel:Disable(...)
    self:OnDisable(...)
end


function BaseViewModel:Destroy()
    self:OnDestroy()
end


function BaseViewModel:OnInit()

end


function BaseViewModel:OnEnable(...)
    
end


function BaseViewModel:OnDisable(...)
    
end


function BaseViewModel:OnDestroy()
    
end

return  BaseViewModel